﻿using MeetAI.Model;
using MeetAI.Model.DTO;
using MeetAI.Model.VO;
using MeetAI.Repository.IRepository;
using MeetAI.Service.IService;
using MeetAI.Utility;
using SqlSugar;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Linq.Expressions;
using System.Text;
using System.Threading.Tasks;

namespace MeetAI.Service
{
    public class Dy_ClassType_Service : BaseService<dy_classtype>, IDy_ClassType_Service
    {
        private readonly IDy_ClassType_Repository _repository;
        public Dy_ClassType_Service(IDy_ClassType_Repository repository) : base(repository)
        {
            _repository = repository;
        }
        public async Task<IEnumerable<dy_classtype_vo>> getClassType(Expression<Func<dy_classtype, bool>> exp)
        {
            var lst = await _repository.FindListByClauseAsync(exp);
            return lst.Select(s => new dy_classtype_vo
            {
                classId = s.tid,
                molds = s.molds,
                tname = s.classname,
                litpic = string.Format("{0}{1}", staticDomain, s.mobilepic)
            });
        }

        public async Task<IEnumerable<dy_classtype_vo>> getClassTypeList(dy_classtype_dto dto)
        {
            var where = PredicateBuilder.True<dy_classtype>();
            where = where.And(s => s.mshow.Equals(1));
            if (dto.pid.HasValue)
            {
                where = where.And(s => s.pid.Equals(dto.pid));
            }
            dto.order = "orders desc";
            var list = await _repository.FindPagedListAsync(where, dto.order, dto.page.Value, dto.size.Value);
            return list.Select(s => new dy_classtype_vo
            {
                classId = s.tid,
                molds = s.molds,
                tname = s.classname,
                litpic = string.Format("{0}{1}", staticDomain, s.mobilepic)
            });
        }
    }
}
